import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:flutterdemo/0demo/ui/ui_page.dart';

void main() {
  testWidgets("test input active code", (WidgetTester tester) async {
    await tester.pumpWidget(MaterialApp(
      home: UIPage(),
    ));

    // find all widgets we need
    final inputFiled = find.byWidgetPredicate((widget) {
      return widget is TextField &&
          widget.keyboardType == TextInputType.number &&
          widget.maxLength == 4;
    });
    final button = find.byKey(Key("activeButton"));

    await tester.enterText(inputFiled, "6789");
    await tester.tap(button);
    await tester.pump();

    // check result
    // Finds [Text] and [EditableText] widgets containing string equal to the
    // `text` argument.
    expect(find.text("6789"), findsNWidgets(2));
  });
}
